<!DOCTYPE html>
<html xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>广告分类管理</title>
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <link rel="stylesheet" href="/plugins/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="/plugins/adminLTE/css/AdminLTE.css">
    <link rel="stylesheet" href="/plugins/adminLTE/css/skins/_all-skins.min.css">
    <link rel="stylesheet" href="/css/style.css">
	<script src="/plugins/jQuery/jquery-2.2.3.min.js"></script>
    <script src="/plugins/bootstrap/js/bootstrap.min.js"></script>
	<div th:insert="/common.html"></div>
</head>

<body class="hold-transition skin-red sidebar-mini"  >
  <!-- .box-body -->
                
                    <div class="box-header with-border">
                        <h3 class="box-title">广告分类管理</h3>
                    </div>

                    <div class="box-body">

                        <!-- 数据表格 -->
                        <div class="table-box">

                            <!--工具栏-->
                            <div class="pull-left">
                                <div class="form-group form-inline">
                                    <div class="btn-group">
                                        <button onclick="newlyBuild()" type="button" class="btn btn-default" title="新建" data-toggle="modal" data-target="#editModal" ><i class="fa fa-file-o"></i> 新建</button>
                                        <button type="button" class="btn btn-default" title="删除" ><i class="fa fa-trash-o"></i> 删除</button>
                                        <button type="button" class="btn btn-default" title="开启" onclick='confirm("你确认要开启吗？")'><i class="fa fa-check"></i> 开启</button>
                                        <button type="button" class="btn btn-default" title="屏蔽" onclick='confirm("你确认要屏蔽吗？")'><i class="fa fa-ban"></i> 屏蔽</button>
                                        <button type="button" class="btn btn-default" title="刷新" onclick="window.location.reload();"><i class="fa fa-refresh"></i> 刷新</button>
                                    </div>
                                </div>
                            </div>
                            <div class="box-tools pull-right">
                                <div class="has-feedback">
							        名称：<input >	<button class="btn btn-default" >查询</button>                                    
                                </div>
                            </div>
                            <!--工具栏/-->

			                  <!--数据列表-->
			                  <table id="dataList" class="table table-bordered table-striped table-hover dataTable">
<!--			                      <thead>-->
<!--			                          <tr>-->
<!--			                              <th class="" style="padding-right:0px">-->
<!--			                                  <input id="selall" type="checkbox" class="icheckbox_square-blue">-->
<!--			                              </th> -->
<!--										  <th class="sorting_asc">分类ID</th>-->
<!--									      <th class="sorting">分类名称</th>-->
<!--									      <th class="sorting">分组</th>-->
<!--									      <th class="sorting">KEY</th>-->
<!--									      <th class="sorting">状态</th>								      							-->
<!--					                      <th class="text-center">操作</th>-->
<!--			                          </tr>-->
<!--			                      </thead>-->
<!--			                      <tbody>-->
<!--			                          <tr>-->
<!--			                              <td><input  type="checkbox" ></td>			                              -->
<!--				                          <td>1</td>-->
<!--									      <td>首页轮播广告</td>-->
<!--									      <td>首页广告</td>-->
<!--									      <td>index</td>-->
<!--		                                  <td>-->
<!--			                                 <span>无效</span>	-->
<!--										     <span>有效</span>										                                    -->
<!--		                                  </td>-->
<!--		                                  <td class="text-center">                                           -->
<!--		                                 	  <button type="button" class="btn bg-olive btn-xs" data-toggle="modal" data-target="#editModal" >修改</button>                                           -->
<!--		                                  </td>-->
<!--			                          </tr>-->
<!--			                      </tbody>-->
			                  </table>
			                  <!--数据列表/--> 
                        </div>
                        <!-- 数据表格 /-->
                     </div>
                    <!-- /.box-body -->
	            <!-- 分页 -->
				
				                
<!-- 编辑窗口 -->
<div class="modal fade" id="editModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog" >
	<div class="modal-content">
		<div class="modal-header">
			<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
			<h3 id="myModalLabel">广告分类编辑</h3>
		</div>
		<div class="modal-body">							
			
			<table class="table table-bordered table-striped"  width="800px">
		      	<tr>
		      		<td>分类名称</td>
		      		<td>
						<input name="name"  class="form-control" placeholder="分类名称">
						<input name="id" type="hidden"  class="form-control" placeholder="分类id">
					</td>
		      	</tr>
<!--		      	<tr>-->
<!--		      		<td>分组</td>-->
<!--		      		<td><input  class="form-control" placeholder="分组">  </td>-->
<!--		      	</tr>	-->
<!--			    <tr>-->
<!--		      		<td>KEY</td>-->
<!--		      		<td><input  class="form-control" placeholder="KEY">  </td>-->
<!--		      	</tr>		      -->
<!--		      	<tr>-->
<!--		      		<td>是否有效</td>-->
<!--		      		<td>-->
<!--		      		 <input type="checkbox" class="icheckbox_square-blue" >-->
<!--		      		</td>-->
<!--		      	</tr>  	-->
			 </table>				
			
		</div>
		<div class="modal-footer">						
			<button id="insetId" onclick="insertGet()" class="btn btn-success" data-dismiss="modal" aria-hidden="true">保存</button>
			<button id="updateId" onclick="updateGet()" class="btn btn-success" data-dismiss="modal" aria-hidden="true">修改</button>
			<button class="btn btn-default" data-dismiss="modal" aria-hidden="true">关闭</button>
		</div>
	  </div>
	</div>
</div>

    
</body>
<script type="text/javascript">
	$('#dataList').bootstrapTable({
		url: "/contentCategory/getContentCategoryAll", //请求后台的URL（*）
		method: 'get',                      //请求方式（*）
		// contentType: "application/x-www-form-urlencoded",/*使用post*/
		// toolbar: '#sdfname',              //工具按钮用哪个容器
		striped: true,                      //是否显示行间隔色
		cache: false,                       //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
		pagination: true,                   //是否显示分页（*）
		sidePagination: "client",           //分页方式：client客户端分页，server服务端分页（*）
		pageNumber: 1,                      //初始化加载第一页，默认第一页,并记录
		pageSize: 10,                        //每页的记录行数（*）
		pageList: [1, 3, 5],                //可供选择的每页的行数（*）
		showColumns: true,                  //是否显示所有的列（选择显示的列）
		showRefresh: true,                  //是否显示刷新按钮
		minimumCountColumns: 1,             //最少允许的列数
		clickToSelect: true,                //是否启用点击选中行
		showToggle: true,                   //是否显示详细视图和列表视图的切换按钮
		detailView: true,                  //是否显示父子表
		//得到查询的参数
		queryParams : function (params) {
		},
		columns: [{
			checkbox: true,
			visible: true                  //是否显示复选框
		}, {
			field: 'id',
			title: '广告分类ID'
		}, {
			field: 'name',
			title: '广告分类名称'
		},{
			field:'id',
			title: '操作',
			width: 120,
			align: 'center',
			valign: 'middle',
			formatter: function (value, row, index) {
				var id = value;
				var result = "";
				result += '<button onclick="updateEcho('+id+')" type="button" class="btn bg-olive btn-xs" data-toggle="modal" data-target="#editModal" >修改</button> ';
				result += "<a href='javascript:DeleteById(" + id + ")' class='btn btn-xs red' title='删除'><span class='glyphicon glyphicon-remove'></span></a>";
				return result;
			}
		}
		],
		onLoadError: function () {
			toastr.error("数据加载失败！");
		},onDblClickRow: function (row, $element) {//双击事件
		}
	})
	/*查询*/
	function query() {
		$("#dataList").bootstrapTable("refresh");
	}
	function newlyBuild() {
		$('#updateId').hide();
		$('#insetId').show();
	}
	function insertGet() {
		$.ajax({
			url: "/contentCategory/addContentCategory",
			dataType: "json",
			type: "post",
			data: {
				name:$("[name='name']").val()
			},
			async:false,
			success:function (result) {
				if (result.code == 10000){
					query();
					toastr.success(result.message)
				}else if(result.code == 9999){
					toastr.error(result.message)
				}
			},error:function (result) {
				alert(result.message)
			}
		})
	}
	function updateEcho(id) {
		$('#insetId').hide();
		$('#updateId').show();
		$.ajax({
			url: "/contentCategory/updateContentCategoryEcho",
			dataType: "json",
			type: "post",
			data: {
				id:id
			},
			async:false,
			success:function (result) {
				var contentCategory = result.data;
				if (result.code == 10000){
					$("[name='name']").val(contentCategory.name)
					$("[name='id']").val(contentCategory.id)
				}else if(result.code == 9999){
					toastr.error(result.message)
				}
			},error:function (result) {
				alert(result.message)
			}
		})
	}
	function updateGet() {
		$('#insetId').hide();
		$('#updateId').show();
		$.ajax({
			url: "/contentCategory/updateContentCategory",
			dataType: "json",
			type: "post",
			data: {
				name:$("[name='name']").val(),
				id:$("[name='id']").val()
			},
			async:false,
			success:function (result) {
				var contentCategory = result.data;
				if (result.code == 10000){
					query();
					toastr.success(result.message)
				}else if(result.code == 9999){
					toastr.error(result.message)
				}
			},error:function (result) {
				alert(result.message)
			}
		})
	}
	function DeleteById(id) {
		if (confirm("确定要删除吗?")) {
			$.ajax({
				url: "/contentCategory/deleteContentCategory",
				type: "post",
				dataType: "json",
				data: {
					id:id
				},
				async: false,
				success: function (result) {
					if (result.code == 10000) {
						toastr.success(result.message);
						query();
					} else if (result.code == 9999){
						toastr.error(result.message);
					}
				},
				error: function (result) {
					toastr.error("错误");
				}
			})
		}
	}
</script>
</html>